package com.lagou.edu.converter;

import org.springframework.core.convert.converter.Converter;

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * 日期类型转换器
 * String 源类型
 * Date   目标类型
 */
public class DateConverter implements Converter<String, Date> {

    @Override
    public Date convert(String source) {
        LocalDate localDate = LocalDate.parse(source);
        ZoneId zoneId = ZoneId.systemDefault();
        Instant instant = localDate.atStartOfDay().atZone(zoneId).toInstant();
        return Date.from(instant);
    }
}
